﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace sqlmanagewpf
{
    /// <summary>
    /// Interaction logic for UserControl1.xaml
    /// </summary>
    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
        }

        private void DatabaseTreeView_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            //TreeViewItem clickedItem = FindAncestor<TreeViewItem>((DependencyObject)e.OriginalSource);

            //if (clickedItem != null)
            //{
            //    // 在这里执行右键单击的逻辑，例如显示右键菜单或执行特定操作
            //    // clickedItem 就是被右键点击的 TreeViewItem
            //    // 例如，可以获取其 DataContext，处理节点的数据等
            //}

            (this.DataContext as UserControl1ViewModel).YourText += (e.OriginalSource as TextBlock).Text;


        }

        private static T FindAncestor<T>(DependencyObject current)
    where T : DependencyObject
        {
            do
            {
                if (current is T ancestor)
                {
                    return ancestor;
                }
                current = VisualTreeHelper.GetParent(current);
            }
            while (current != null);
            return null;
        }
    }
}
